package com.airsystem.pos.bengkel.service.parser;

import org.apache.log4j.Logger;

import com.airsystem.pos.bengkel.entity.DetailKendaraan;
import com.airsystem.pos.bengkel.entity.DetailLayanan;
import com.airsystem.pos.bengkel.entity.Layanan;
import com.airsystem.pos.bengkel.interfaces.IParser;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class LayananParser implements IParser<DetailLayanan, Object> {
	private static final Logger LOG = Logger.getLogger(LayananParser.class.getSimpleName());

	public DetailLayanan doParse(Object data) {
		DetailLayanan dtLayanan = null;
		Object[] objects = (Object[]) data;

		for (Object item : objects) {
			if (isDetailLayananInstance(item)) {
				dtLayanan = (DetailLayanan) item;
			} else if (isLayananInstance(item)) {
				dtLayanan.setLayanan((Layanan) item);
			} else if (isDetailKendaraanInstance(item)) {
				dtLayanan.setDetail_kendaraan((DetailKendaraan) item);
			} else {
				LOG.info("Instance result is " + item.toString());
			}

			continue;
		}

		return dtLayanan;
	}

	private boolean isLayananInstance(Object object) {
		return (object instanceof Layanan);
	}

	private boolean isDetailLayananInstance(Object object) {
		return (object instanceof DetailLayanan);
	}

	private boolean isDetailKendaraanInstance(Object object) {
		return (object instanceof DetailKendaraan);
	}
}